<?php
include "includeFiles.php";
//if(empty($_SESSION['user_id'])) echo "<script>location.href='login.php';<//script>";

 function unsetArray($array,$delarr){
		foreach ($array as $bkey=>$bvalue){
			foreach ($delarr as $key=>$value){
				if($value == $bkey){
				unset($array[$bkey]);		
			    }
		     }
	    }
		return $array;
	}


function insert($arr,$table){
    	if($arr){
    		foreach ($arr as $key=>$value){
    			@$fild[]  = "`".$key."`";
    			@$vals[]  = "'".$value."'";
    		}
    	}
    	$fild = implode($fild,",");
    	$vals = implode($vals,",");
    	return @$sql  =" insert into ".$table."(".$fild.")values(".$vals.")";
    }
	
	
	function update($arr,$table,$where){
		$str="UPDATE `$table` SET ";
		foreach ($arr as $key=>$value){
			$str_key.="`".$key."`='".$value."',";
		}
		$str_key=substr($str_key,0,-1);
		foreach ($where as $key=>$value){
			$sql_where.="`$key`"."='".$value."' AND";
		}
		$sql_where=substr($sql_where,0,-4);
		return $sql_update=$str.$str_key." WHERE ".$sql_where.";";
		
	}
	
if($_POST['action'] == 'addactivity'){
	$table = "Code_activity";
	$post  = unsetArray($_POST,$arr=array('action'));
	$sql   = insert($post,$table);
	$msg   = $objDb->query($sql);
	if($msg){
		echo "<script>alert('添加成功！');location.href='3g_activity_add.php';</script>";
	}else{
		echo "<script>alert('添加失败！');location.href='3g_activity_add.php';</script>";
	}	
} 

if($_POST['action'] == 'updateactivity'){
	$table = "Code_activity";
	$post  = unsetArray($_POST,$arr=array('action','id'));
	$where = array("id"=>$_GET['id']);
	 $sql   = update($post,$table,$where);
	//die;
	$msg   = $objDb->query($sql);
	if($msg){
		echo "<script>alert('更新成功！');location.href='3g_activity_add.php?id=".$_GET['id']."';</script>";
	}else{
		echo "<script>alert('更新失败！');location.href='3g_activity_add.php?id=".$_GET['id']."';</script>";
	}	

}





?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $C['Title'];?></title>
<Link href="../uploadfile/ico/<?php echo $C['ICO'];?>" rel="Shortcut Icon">
<meta name="Keywords" content="<?php echo $C['Keywords'];?>">
<meta name="description" content="<?php echo $C['Description'];?>">
<Meta name="Copyright" Content="<?php echo $C['CopyRight'];?>">
<link href="css/css.css" rel="stylesheet" type="text/css" />
<link charset="utf-8" rel="stylesheet" href="css/alipay.css">
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
</head>
<body id="mainbody">
<?php include_once('header.php');?>
<!--主体布局-->
<div class="main">
  <div class="locahostDIv"> <span>当前位置：<a href="index.php&cityid=<?=$cityid?>">首页</a></span> >
  <?
   if($keyword)	{ echo "搜索中"; }else{
  
  ?>
   <a href="on.php?hid=110&cityid=<?=$cityid?>">2G号码套包</a> > <a href="on.php?cateid=<?=$cateid?>&cityid=<?=$cityid?>"><?=$alink=$info->getProLinks($cateid)?></a> 
   <? }?>
   
   </div>
  <div class="contant">
    <div class="left">
      <div class="fen">
        <div class="box">
          <div class="tital">
            <div class="tit"><em>产品分类</em></div>
          </div>
          <div class="main2">
            <div class="sorttab">
              <ul class="tab">
	<?php	
	$vm=$info->getProMenu(110);
	if($vm){
	foreach($vm as $key=>$value){
	 ?>
        <li class="l1"><a href="on.php?cateid=<?=$value['SysProCategoryID']?>&cityid=<?=$cityid?>"><?=$value['CateName']?></a></li>
            <? }}?>
              </ul>
            </div>
          </div>
        </div>
        <div class="bot"></div>
      </div>
    </div>
    <div class="right">
      <div class="about2">
        <div class="box">
          <div class="main1">
              <div class="pageInfo">
              
              <h1><a href="3g_admin_list.php">管理列表</a> | <a href="3gadd.php">新增</a> </h1>
         <form action="3gadd.php" method="post">
         
         <? if($_GET['id']){?>
             <input name="action" type="hidden" value="updateactivity" />
             <input name="id" type="hidden" value="<?=$_GET['id']?>" />
             
             <?  
			  $SQL2=" select * from Code_activity where id = $id ";
		      $objDb->query($SQL2);
		      $msg = $objDb->get_data();
			 ?>
             
             <? } else {?>
              <input name="action" type="hidden" value="addactivity" />
             <? }?>
                 <table>
            <?
                $SQL3="  select COLUMN_NAME,column_comment from INFORMATION_SCHEMA.Columns where table_name='Code_activity' ";
				$objDb->query($SQL3);
		        $result = $objDb->get_data();
			    if($result){
					foreach($result as $key=>$value){
						 if($key == 0 ) continue;
				?>  <tr><td>
                
                <label> <?php echo $value['column_comment'];?></label></td>
                <td>
                   <input name="<?=$value['COLUMN_NAME']?>" id="<?=$value['COLUMN_NAME']?>"  type="text" value="<?=$msg[0][$value['COLUMN_NAME']]?>" />
                   </td> </tr>
            <? }} ?>
            <tr><td colspan="2">
            <center>
            <input type="submit" />
            </center>
              </td></tr>
               </table>
            </form>
            
            <script>
			  function din(a){
			    $('#dinner_view').text(a);
			 }
			
			  function act(a){
			    $('#activity_view').text(a);
			 }

              
            </script>
            </div>            
          
          </div>
        </div>
		<div align="center"> <?php // echo $pagenav; ?></div>
        <div class="bot"></div>
      </div>
    </div>
  </div>
  <div class="gehang"></div>
  <div style="width:980px;height:100%;overflow:hidden;margin-top:10px"> <img src="images/copy_line.jpg" /><br />
    <br />
    <br />
    <img src="images/copy.jpg" />
    <?php include_once('help.php');?>
    <img src="images/copy_line.jpg" /> </div>
</div>
<div class="clear"></div>
<?php include_once('footer.php');?>

</body>
</html>
